//
//  QCViewController.m
//  QNJSDK
//
//  Created by miaoliujie@xianjincard.com on 06/22/2018.
//  Copyright (c) 2018 miaoliujie@xianjincard.com. All rights reserved.
//

#import "QCViewController.h"
#import <QNJSDK/QnjSDK.h>
@interface QCViewController ()<UITextFieldDelegate>
@property (nonatomic, strong)UITextField *textField;
@property (nonatomic, strong)UITextField *phoneTextField;
@property (nonatomic, strong)UITextField *UUIDTextField;
@property (nonatomic, strong)UITextField *themeColortf;
@end

@implementation QCViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    // Do any additional setup after loading the view, typically from a nib.
    
    UIButton *button3 = [[UIButton alloc]initWithFrame:CGRectMake(10, 88, 200, 40)];
    [self.view addSubview:button3];
    [button3 addTarget:self action:@selector(goTab) forControlEvents:UIControlEventTouchUpInside];
    [button3 setTitle:@"进入主Tab" forState:UIControlStateNormal];
    [button3 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    button3.backgroundColor = [UIColor redColor];
    button3.hidden = YES;
    
    _phoneTextField = [[UITextField alloc]initWithFrame:CGRectMake(10, CGRectGetMaxY(button3.frame)+50, 200, 30)];
    _phoneTextField.borderStyle = UITextBorderStyleBezel;
    _phoneTextField.placeholder = @"请输入手机号";
    [self.view addSubview:_phoneTextField];
    
    _UUIDTextField = [[UITextField alloc]initWithFrame:CGRectMake(10, CGRectGetMaxY(_phoneTextField.frame)+10, 200, 30)];
    _UUIDTextField.borderStyle = UITextBorderStyleBezel;
    _UUIDTextField.placeholder = @"请输入UUID";
    [self.view addSubview:_UUIDTextField];
    UIButton *button4 = [[UIButton alloc]initWithFrame:CGRectMake(10, CGRectGetMaxY(self.UUIDTextField.frame) + 10, 200, 40)];
    [self.view addSubview:button4];
    [button4 addTarget:self action:@selector(goLoginTab) forControlEvents:UIControlEventTouchUpInside];
    [button4 setTitle:@"登入SDK" forState:UIControlStateNormal];
    [button4 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    button4.backgroundColor = [UIColor redColor];
    
    
    UIButton *button5 = [[UIButton alloc]initWithFrame:CGRectMake(10, CGRectGetMaxY(button4.frame) + 10, 200, 40)];
    [self.view addSubview:button5];
    [button5 addTarget:self action:@selector(goJS) forControlEvents:UIControlEventTouchUpInside];
    [button5 setTitle:@"JSApi调试页" forState:UIControlStateNormal];
    [button5 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    button5.backgroundColor = [UIColor redColor];
    
    
    _themeColortf = [[UITextField alloc]initWithFrame:CGRectMake(10, CGRectGetMaxY(button5.frame) + 10, 300, 40)];
    _themeColortf.borderStyle = UITextBorderStyleBezel;
    [self.view addSubview:_themeColortf];
    _themeColortf.placeholder = @"请输入主题色,示例：#FFD701";
}

- (void)goJS{
}
- (void)goLoginTab {
    NSString *uuid = @"13918526053";
    NSString *phone = uuid;
    [QnjSDK getColor:_themeColortf.text];
    [QnjSDK initUUIDS:_UUIDTextField.text.length != 0 ? _UUIDTextField.text : uuid phoneNum:_phoneTextField.text.length != 0 ? _phoneTextField.text : phone initInfo:^(NSError *error) {
        if (error) {
            NSLog(@"%@", error);
            
            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:[NSString stringWithFormat:@"%ld--%@",[error.userInfo[@"code"] integerValue],error.userInfo[@"message"]] delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
            [alert show];
            
            //            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:[NSString stringWithFormat:@"%ld--%@",[error.userInfo[@"code"] integerValue],error.userInfo[@"message"]] preferredStyle:UIAlertControllerStyleAlert];
            //            [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            //
            //            }]];
            //            [self presentViewController:alert animated:YES completion:nil];
        }
    }];
    [QnjSDK setGoBackBlock:^{
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"从sdk返回" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
    }];
}
- (void)goTab{
    
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self.textField resignFirstResponder];
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    return YES;
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end
